﻿using Gfw.Repositories.Account;
using Gfw.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gfw.Infrastructure.Facilities
{
    /// <summary>
    /// 结算担保，五天后返还给卖家
    /// </summary>
    public class WarrantSettlement : IFacility
    {
        #region 构造函数

        public WarrantSettlement()
        {

        }

        #endregion

        #region IFacility 成员

        public void Execute(UnitOfWork unitOfWork = null)
        {
            UnitOfWork work = unitOfWork ?? new UnitOfWork();
            ActUserWarrantRepository repository = new ActUserWarrantRepository();
            var list = repository.Query();

            foreach (var item in list)
            {
                try
                {
                    TransferFacility.ExecuteWarrantReturn(item.ToUserId, item.ToUserLoginName,
                        item.Userid, item.TradeDate.Value);
                }
                catch (System.Exception ex)
                {
                    throw new Gfw.Infrastructure.ExceptionImpl.GfwVerifyException(ex.Message);
                }
            }
        }

        #endregion
    }
}
